using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Data;
using ClusteringAnalysis.Mediators;
using Slaks.ClusteringInfo;
using Slaks.DocumentSerialization.Dictionary;
using Slaks.DocumentSerialization.Document;
using Slaks.Graphs;
using Slaks.Graphs.GraphBuilder;
using Slaks.Graphs.GraphBuilder.SchenkerDictionary;

namespace ClusteringAnalysis
{

	public enum RepresentationClass { Vector, Graph };
	public enum DistanceType { Cos, Jacaard, Mcs, Wgu};
	public enum VectorRepresentationType { Standard , Simple};
	public enum GraphRepresentationType { StandardSchenker , SimpleSchenker, NDistanceSchenker,
	                                      NSimpleDistanceSchenker, RawFrequencySchenker, NormalizedFrequencySchenker};

	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox m_dictionaryGB;
		private System.Windows.Forms.TextBox m_dictionaryTB;
		private System.Windows.Forms.Button m_dictionaryBtn;
		private System.Windows.Forms.OpenFileDialog openFileDialog;
		private System.Windows.Forms.ComboBox m_vectorRepCB;
		private System.Windows.Forms.RadioButton m_vectorRB;
		private System.Windows.Forms.RadioButton m_graphRB;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.ComboBox m_graphRepCB;
		private System.Windows.Forms.ListView m_clustersLV;
		private System.Windows.Forms.GroupBox m_clustersGB;
		private System.Windows.Forms.Button m_clustersAddBtn;
		private System.Windows.Forms.Button m_clustersClearBtn;
		private System.Windows.Forms.GroupBox m_resultsGB;
		private System.Windows.Forms.TextBox m_dunnIndexTB;
		private System.Windows.Forms.Label m_dunnIndexL;
		private System.Windows.Forms.GroupBox m_startGB;
		private System.Windows.Forms.Button m_proceedBtn;
		private System.Windows.Forms.ColumnHeader m_clusterFilesCH;


		private RepresentationClass m_currentRepresentationClass;
		private DistanceType m_currentDistanceType;
		private VectorRepresentationType m_currentVectorRepresentationType;
		private System.Windows.Forms.NumericUpDown m_distanceValueUD;
		private System.Windows.Forms.Label m_distanceValueL;
		private System.Windows.Forms.GroupBox m_seriesPathGB;
		private System.Windows.Forms.Button m_seriesPathBtn;
		private System.Windows.Forms.TextBox m_seriesPathTB;
		private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
		private System.Windows.Forms.ListView m_loggingLV;
		private System.Windows.Forms.RadioButton m_jacaardDistanceRB;
		private System.Windows.Forms.RadioButton m_cosineDistanceRB;
		private System.Windows.Forms.RadioButton m_wguDistanceRB;
		private System.Windows.Forms.RadioButton m_mcsDistanceRB;
		private System.Windows.Forms.GroupBox m_vectorRepGB;
		private System.Windows.Forms.GroupBox m_graphRepGB;
		private GraphRepresentationType m_currentGraphRepresentationType;
		private System.Windows.Forms.ColumnHeader m_logCH;
		private System.Windows.Forms.TextBox m_dunnIndexSTDTB;
		private System.Windows.Forms.Label m_dunnIndexSTDL;
		private ResultMediator m_resultMediator;

		public Form1()
		{
			InitializeComponent();

			openFileDialog.Filter = "Xml file|*.xml|All files|*.*";
			openFileDialog.RestoreDirectory = true;
			

			m_vectorRepCB.Items.Add(VectorRepresentationType.Standard);
			m_vectorRepCB.Items.Add(VectorRepresentationType.Simple);

			m_graphRepCB.Items.Add(GraphRepresentationType.StandardSchenker);
			m_graphRepCB.Items.Add(GraphRepresentationType.SimpleSchenker);
			m_graphRepCB.Items.Add(GraphRepresentationType.NDistanceSchenker);
			m_graphRepCB.Items.Add(GraphRepresentationType.NSimpleDistanceSchenker);
			m_graphRepCB.Items.Add(GraphRepresentationType.RawFrequencySchenker);
			m_graphRepCB.Items.Add(GraphRepresentationType.NormalizedFrequencySchenker);

			m_vectorRepCB.SelectedIndex = 0;
			m_graphRepCB.SelectedIndex = 0;

			this.SetRepresentationClass(RepresentationClass.Vector);

			m_resultMediator = new ResultMediator(m_loggingLV,m_dunnIndexTB,m_dunnIndexSTDTB);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.m_dictionaryGB = new System.Windows.Forms.GroupBox();
			this.m_dictionaryBtn = new System.Windows.Forms.Button();
			this.m_dictionaryTB = new System.Windows.Forms.TextBox();
			this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
			this.m_vectorRepGB = new System.Windows.Forms.GroupBox();
			this.m_jacaardDistanceRB = new System.Windows.Forms.RadioButton();
			this.m_cosineDistanceRB = new System.Windows.Forms.RadioButton();
			this.m_vectorRB = new System.Windows.Forms.RadioButton();
			this.m_vectorRepCB = new System.Windows.Forms.ComboBox();
			this.m_distanceValueL = new System.Windows.Forms.Label();
			this.m_distanceValueUD = new System.Windows.Forms.NumericUpDown();
			this.m_graphRB = new System.Windows.Forms.RadioButton();
			this.m_graphRepCB = new System.Windows.Forms.ComboBox();
			this.m_clustersLV = new System.Windows.Forms.ListView();
			this.m_clusterFilesCH = new System.Windows.Forms.ColumnHeader();
			this.m_clustersGB = new System.Windows.Forms.GroupBox();
			this.m_clustersClearBtn = new System.Windows.Forms.Button();
			this.m_clustersAddBtn = new System.Windows.Forms.Button();
			this.m_resultsGB = new System.Windows.Forms.GroupBox();
			this.m_dunnIndexL = new System.Windows.Forms.Label();
			this.m_dunnIndexTB = new System.Windows.Forms.TextBox();
			this.m_startGB = new System.Windows.Forms.GroupBox();
			this.m_proceedBtn = new System.Windows.Forms.Button();
			this.m_seriesPathGB = new System.Windows.Forms.GroupBox();
			this.m_seriesPathBtn = new System.Windows.Forms.Button();
			this.m_seriesPathTB = new System.Windows.Forms.TextBox();
			this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
			this.m_loggingLV = new System.Windows.Forms.ListView();
			this.m_logCH = new System.Windows.Forms.ColumnHeader();
			this.m_graphRepGB = new System.Windows.Forms.GroupBox();
			this.m_wguDistanceRB = new System.Windows.Forms.RadioButton();
			this.m_mcsDistanceRB = new System.Windows.Forms.RadioButton();
			this.m_dunnIndexSTDTB = new System.Windows.Forms.TextBox();
			this.m_dunnIndexSTDL = new System.Windows.Forms.Label();
			this.m_dictionaryGB.SuspendLayout();
			this.m_vectorRepGB.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.m_distanceValueUD)).BeginInit();
			this.m_clustersGB.SuspendLayout();
			this.m_resultsGB.SuspendLayout();
			this.m_startGB.SuspendLayout();
			this.m_seriesPathGB.SuspendLayout();
			this.m_graphRepGB.SuspendLayout();
			this.SuspendLayout();
			// 
			// m_dictionaryGB
			// 
			this.m_dictionaryGB.Controls.Add(this.m_dictionaryBtn);
			this.m_dictionaryGB.Controls.Add(this.m_dictionaryTB);
			this.m_dictionaryGB.Location = new System.Drawing.Point(16, 8);
			this.m_dictionaryGB.Name = "m_dictionaryGB";
			this.m_dictionaryGB.Size = new System.Drawing.Size(736, 64);
			this.m_dictionaryGB.TabIndex = 0;
			this.m_dictionaryGB.TabStop = false;
			this.m_dictionaryGB.Text = "Dictionary";
			// 
			// m_dictionaryBtn
			// 
			this.m_dictionaryBtn.Anchor = System.Windows.Forms.AnchorStyles.Top;
			this.m_dictionaryBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_dictionaryBtn.Location = new System.Drawing.Point(652, 24);
			this.m_dictionaryBtn.Name = "m_dictionaryBtn";
			this.m_dictionaryBtn.Size = new System.Drawing.Size(72, 24);
			this.m_dictionaryBtn.TabIndex = 1;
			this.m_dictionaryBtn.Text = "...";
			this.m_dictionaryBtn.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_dictionaryTB
			// 
			this.m_dictionaryTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.m_dictionaryTB.Location = new System.Drawing.Point(8, 24);
			this.m_dictionaryTB.Name = "m_dictionaryTB";
			this.m_dictionaryTB.Size = new System.Drawing.Size(632, 20);
			this.m_dictionaryTB.TabIndex = 0;
			this.m_dictionaryTB.Text = "";
			// 
			// m_vectorRepGB
			// 
			this.m_vectorRepGB.Controls.Add(this.m_jacaardDistanceRB);
			this.m_vectorRepGB.Controls.Add(this.m_cosineDistanceRB);
			this.m_vectorRepGB.Controls.Add(this.m_vectorRB);
			this.m_vectorRepGB.Controls.Add(this.m_vectorRepCB);
			this.m_vectorRepGB.Location = new System.Drawing.Point(16, 160);
			this.m_vectorRepGB.Name = "m_vectorRepGB";
			this.m_vectorRepGB.Size = new System.Drawing.Size(400, 144);
			this.m_vectorRepGB.TabIndex = 1;
			this.m_vectorRepGB.TabStop = false;
			this.m_vectorRepGB.Text = "Vector Representations";
			// 
			// m_jacaardDistanceRB
			// 
			this.m_jacaardDistanceRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_jacaardDistanceRB.Location = new System.Drawing.Point(288, 72);
			this.m_jacaardDistanceRB.Name = "m_jacaardDistanceRB";
			this.m_jacaardDistanceRB.TabIndex = 4;
			this.m_jacaardDistanceRB.Text = "Jacaard";
			this.m_jacaardDistanceRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_cosineDistanceRB
			// 
			this.m_cosineDistanceRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_cosineDistanceRB.Location = new System.Drawing.Point(288, 32);
			this.m_cosineDistanceRB.Name = "m_cosineDistanceRB";
			this.m_cosineDistanceRB.TabIndex = 3;
			this.m_cosineDistanceRB.Text = "Cosine";
			this.m_cosineDistanceRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_vectorRB
			// 
			this.m_vectorRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_vectorRB.Location = new System.Drawing.Point(8, 24);
			this.m_vectorRB.Name = "m_vectorRB";
			this.m_vectorRB.Size = new System.Drawing.Size(64, 24);
			this.m_vectorRB.TabIndex = 2;
			this.m_vectorRB.Text = "Vector";
			this.m_vectorRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_vectorRepCB
			// 
			this.m_vectorRepCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.m_vectorRepCB.Location = new System.Drawing.Point(8, 56);
			this.m_vectorRepCB.Name = "m_vectorRepCB";
			this.m_vectorRepCB.Size = new System.Drawing.Size(200, 21);
			this.m_vectorRepCB.TabIndex = 0;
			// 
			// m_distanceValueL
			// 
			this.m_distanceValueL.Location = new System.Drawing.Point(16, 96);
			this.m_distanceValueL.Name = "m_distanceValueL";
			this.m_distanceValueL.TabIndex = 5;
			this.m_distanceValueL.Text = "Distance Value";
			// 
			// m_distanceValueUD
			// 
			this.m_distanceValueUD.Location = new System.Drawing.Point(120, 96);
			this.m_distanceValueUD.Minimum = new System.Decimal(new int[] {
																																			1,
																																			0,
																																			0,
																																			0});
			this.m_distanceValueUD.Name = "m_distanceValueUD";
			this.m_distanceValueUD.Size = new System.Drawing.Size(80, 20);
			this.m_distanceValueUD.TabIndex = 4;
			this.m_distanceValueUD.Value = new System.Decimal(new int[] {
																																		2,
																																		0,
																																		0,
																																		0});
			// 
			// m_graphRB
			// 
			this.m_graphRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_graphRB.Location = new System.Drawing.Point(12, 24);
			this.m_graphRB.Name = "m_graphRB";
			this.m_graphRB.Size = new System.Drawing.Size(64, 24);
			this.m_graphRB.TabIndex = 3;
			this.m_graphRB.Text = "Graph";
			this.m_graphRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_graphRepCB
			// 
			this.m_graphRepCB.Location = new System.Drawing.Point(8, 56);
			this.m_graphRepCB.Name = "m_graphRepCB";
			this.m_graphRepCB.Size = new System.Drawing.Size(192, 21);
			this.m_graphRepCB.TabIndex = 1;
			this.m_graphRepCB.SelectedIndexChanged += new System.EventHandler(this.ClickHandler);
			// 
			// m_clustersLV
			// 
			this.m_clustersLV.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																																									 this.m_clusterFilesCH});
			this.m_clustersLV.GridLines = true;
			this.m_clustersLV.Location = new System.Drawing.Point(8, 24);
			this.m_clustersLV.Name = "m_clustersLV";
			this.m_clustersLV.Size = new System.Drawing.Size(624, 240);
			this.m_clustersLV.TabIndex = 2;
			this.m_clustersLV.View = System.Windows.Forms.View.Details;
			// 
			// m_clusterFilesCH
			// 
			this.m_clusterFilesCH.Text = "Cluster Files";
			this.m_clusterFilesCH.Width = 620;
			// 
			// m_clustersGB
			// 
			this.m_clustersGB.Controls.Add(this.m_clustersClearBtn);
			this.m_clustersGB.Controls.Add(this.m_clustersAddBtn);
			this.m_clustersGB.Controls.Add(this.m_clustersLV);
			this.m_clustersGB.Location = new System.Drawing.Point(16, 312);
			this.m_clustersGB.Name = "m_clustersGB";
			this.m_clustersGB.Size = new System.Drawing.Size(736, 272);
			this.m_clustersGB.TabIndex = 3;
			this.m_clustersGB.TabStop = false;
			this.m_clustersGB.Text = "Clusters";
			// 
			// m_clustersClearBtn
			// 
			this.m_clustersClearBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_clustersClearBtn.Location = new System.Drawing.Point(648, 56);
			this.m_clustersClearBtn.Name = "m_clustersClearBtn";
			this.m_clustersClearBtn.Size = new System.Drawing.Size(64, 24);
			this.m_clustersClearBtn.TabIndex = 4;
			this.m_clustersClearBtn.Text = "Clear";
			this.m_clustersClearBtn.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_clustersAddBtn
			// 
			this.m_clustersAddBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_clustersAddBtn.Location = new System.Drawing.Point(648, 24);
			this.m_clustersAddBtn.Name = "m_clustersAddBtn";
			this.m_clustersAddBtn.Size = new System.Drawing.Size(64, 24);
			this.m_clustersAddBtn.TabIndex = 3;
			this.m_clustersAddBtn.Text = "Add";
			this.m_clustersAddBtn.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_resultsGB
			// 
			this.m_resultsGB.Controls.Add(this.m_dunnIndexSTDL);
			this.m_resultsGB.Controls.Add(this.m_dunnIndexSTDTB);
			this.m_resultsGB.Controls.Add(this.m_dunnIndexL);
			this.m_resultsGB.Controls.Add(this.m_dunnIndexTB);
			this.m_resultsGB.Location = new System.Drawing.Point(768, 8);
			this.m_resultsGB.Name = "m_resultsGB";
			this.m_resultsGB.Size = new System.Drawing.Size(288, 144);
			this.m_resultsGB.TabIndex = 4;
			this.m_resultsGB.TabStop = false;
			this.m_resultsGB.Text = "Results";
			// 
			// m_dunnIndexL
			// 
			this.m_dunnIndexL.Location = new System.Drawing.Point(24, 40);
			this.m_dunnIndexL.Name = "m_dunnIndexL";
			this.m_dunnIndexL.Size = new System.Drawing.Size(96, 23);
			this.m_dunnIndexL.TabIndex = 1;
			this.m_dunnIndexL.Text = "Dunn Index";
			// 
			// m_dunnIndexTB
			// 
			this.m_dunnIndexTB.Location = new System.Drawing.Point(144, 40);
			this.m_dunnIndexTB.Name = "m_dunnIndexTB";
			this.m_dunnIndexTB.Size = new System.Drawing.Size(112, 20);
			this.m_dunnIndexTB.TabIndex = 0;
			this.m_dunnIndexTB.Text = "";
			// 
			// m_startGB
			// 
			this.m_startGB.Controls.Add(this.m_proceedBtn);
			this.m_startGB.Location = new System.Drawing.Point(768, 536);
			this.m_startGB.Name = "m_startGB";
			this.m_startGB.Size = new System.Drawing.Size(280, 48);
			this.m_startGB.TabIndex = 5;
			this.m_startGB.TabStop = false;
			// 
			// m_proceedBtn
			// 
			this.m_proceedBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_proceedBtn.Location = new System.Drawing.Point(16, 16);
			this.m_proceedBtn.Name = "m_proceedBtn";
			this.m_proceedBtn.Size = new System.Drawing.Size(248, 24);
			this.m_proceedBtn.TabIndex = 0;
			this.m_proceedBtn.Text = "Proceed";
			this.m_proceedBtn.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_seriesPathGB
			// 
			this.m_seriesPathGB.Controls.Add(this.m_seriesPathBtn);
			this.m_seriesPathGB.Controls.Add(this.m_seriesPathTB);
			this.m_seriesPathGB.Location = new System.Drawing.Point(16, 88);
			this.m_seriesPathGB.Name = "m_seriesPathGB";
			this.m_seriesPathGB.Size = new System.Drawing.Size(736, 64);
			this.m_seriesPathGB.TabIndex = 6;
			this.m_seriesPathGB.TabStop = false;
			this.m_seriesPathGB.Text = "Series path";
			// 
			// m_seriesPathBtn
			// 
			this.m_seriesPathBtn.Anchor = System.Windows.Forms.AnchorStyles.Top;
			this.m_seriesPathBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_seriesPathBtn.Location = new System.Drawing.Point(652, 24);
			this.m_seriesPathBtn.Name = "m_seriesPathBtn";
			this.m_seriesPathBtn.Size = new System.Drawing.Size(72, 24);
			this.m_seriesPathBtn.TabIndex = 1;
			this.m_seriesPathBtn.Text = "...";
			this.m_seriesPathBtn.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_seriesPathTB
			// 
			this.m_seriesPathTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.m_seriesPathTB.Location = new System.Drawing.Point(8, 24);
			this.m_seriesPathTB.Name = "m_seriesPathTB";
			this.m_seriesPathTB.Size = new System.Drawing.Size(632, 20);
			this.m_seriesPathTB.TabIndex = 0;
			this.m_seriesPathTB.Text = "";
			// 
			// m_loggingLV
			// 
			this.m_loggingLV.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																																									this.m_logCH});
			this.m_loggingLV.GridLines = true;
			this.m_loggingLV.Location = new System.Drawing.Point(768, 168);
			this.m_loggingLV.Name = "m_loggingLV";
			this.m_loggingLV.Size = new System.Drawing.Size(280, 360);
			this.m_loggingLV.TabIndex = 7;
			this.m_loggingLV.View = System.Windows.Forms.View.Details;
			// 
			// m_logCH
			// 
			this.m_logCH.Text = "";
			this.m_logCH.Width = 276;
			// 
			// m_graphRepGB
			// 
			this.m_graphRepGB.Controls.Add(this.m_wguDistanceRB);
			this.m_graphRepGB.Controls.Add(this.m_mcsDistanceRB);
			this.m_graphRepGB.Controls.Add(this.m_graphRepCB);
			this.m_graphRepGB.Controls.Add(this.m_graphRB);
			this.m_graphRepGB.Controls.Add(this.m_distanceValueL);
			this.m_graphRepGB.Controls.Add(this.m_distanceValueUD);
			this.m_graphRepGB.Location = new System.Drawing.Point(424, 160);
			this.m_graphRepGB.Name = "m_graphRepGB";
			this.m_graphRepGB.Size = new System.Drawing.Size(328, 144);
			this.m_graphRepGB.TabIndex = 8;
			this.m_graphRepGB.TabStop = false;
			this.m_graphRepGB.Text = "Graph Representations";
			// 
			// m_wguDistanceRB
			// 
			this.m_wguDistanceRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_wguDistanceRB.Location = new System.Drawing.Point(240, 64);
			this.m_wguDistanceRB.Name = "m_wguDistanceRB";
			this.m_wguDistanceRB.Size = new System.Drawing.Size(72, 24);
			this.m_wguDistanceRB.TabIndex = 7;
			this.m_wguDistanceRB.Text = "WGU";
			this.m_wguDistanceRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_mcsDistanceRB
			// 
			this.m_mcsDistanceRB.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.m_mcsDistanceRB.Location = new System.Drawing.Point(240, 24);
			this.m_mcsDistanceRB.Name = "m_mcsDistanceRB";
			this.m_mcsDistanceRB.Size = new System.Drawing.Size(64, 24);
			this.m_mcsDistanceRB.TabIndex = 6;
			this.m_mcsDistanceRB.Text = "MCS";
			this.m_mcsDistanceRB.Click += new System.EventHandler(this.ClickHandler);
			// 
			// m_dunnIndexSTDTB
			// 
			this.m_dunnIndexSTDTB.Location = new System.Drawing.Point(144, 88);
			this.m_dunnIndexSTDTB.Name = "m_dunnIndexSTDTB";
			this.m_dunnIndexSTDTB.Size = new System.Drawing.Size(112, 20);
			this.m_dunnIndexSTDTB.TabIndex = 2;
			this.m_dunnIndexSTDTB.Text = "";
			// 
			// m_dunnIndexSTDL
			// 
			this.m_dunnIndexSTDL.Location = new System.Drawing.Point(24, 88);
			this.m_dunnIndexSTDL.Name = "m_dunnIndexSTDL";
			this.m_dunnIndexSTDL.Size = new System.Drawing.Size(112, 40);
			this.m_dunnIndexSTDL.TabIndex = 3;
			this.m_dunnIndexSTDL.Text = "Dunn Index Standard Deviation";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(1064, 598);
			this.Controls.Add(this.m_graphRepGB);
			this.Controls.Add(this.m_loggingLV);
			this.Controls.Add(this.m_seriesPathGB);
			this.Controls.Add(this.m_startGB);
			this.Controls.Add(this.m_resultsGB);
			this.Controls.Add(this.m_clustersGB);
			this.Controls.Add(this.m_vectorRepGB);
			this.Controls.Add(this.m_dictionaryGB);
			this.Name = "Form1";
			this.Text = "Form1";
			this.m_dictionaryGB.ResumeLayout(false);
			this.m_vectorRepGB.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.m_distanceValueUD)).EndInit();
			this.m_clustersGB.ResumeLayout(false);
			this.m_resultsGB.ResumeLayout(false);
			this.m_startGB.ResumeLayout(false);
			this.m_seriesPathGB.ResumeLayout(false);
			this.m_graphRepGB.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}

		private void SetRepresentationClass(RepresentationClass repClass)
		{
			if (repClass == RepresentationClass.Vector)
			{
				//m_graphRB.Checked = false;
				m_graphRepCB.Enabled = false;

				//m_vectorRB.Checked = true;
				m_vectorRepCB.Enabled = true;

				m_distanceValueL.Enabled = false;
				m_distanceValueUD.Enabled = false;

				m_mcsDistanceRB.Enabled = false;
				m_wguDistanceRB.Enabled = false;

				m_cosineDistanceRB.Enabled = true;
				m_jacaardDistanceRB.Enabled = true;

				if (m_cosineDistanceRB.Checked == false && m_jacaardDistanceRB.Checked == false)
				{
					m_cosineDistanceRB.Checked = true;
					m_currentDistanceType = DistanceType.Cos;
				}
			}
			else
			{
				//m_graphRB.Checked = true;
				m_graphRepCB.Enabled = true;

				//m_vectorRB.Checked = false;
				m_vectorRepCB.Enabled = false;

				m_mcsDistanceRB.Enabled = true;
				m_wguDistanceRB.Enabled = true;

				m_cosineDistanceRB.Enabled = false;
				m_jacaardDistanceRB.Enabled = false;

				if (m_mcsDistanceRB.Checked == false && m_wguDistanceRB.Checked == false)
				{
					m_mcsDistanceRB.Checked = true;
					m_currentDistanceType = DistanceType.Mcs;
				}

				if ((GraphRepresentationType)m_graphRepCB.SelectedItem == GraphRepresentationType.NDistanceSchenker ||
					  (GraphRepresentationType)m_graphRepCB.SelectedItem == GraphRepresentationType.NSimpleDistanceSchenker
					)
				{
					m_distanceValueL.Enabled = true;
					m_distanceValueUD.Enabled = true;
				}
				else
				{
					m_distanceValueL.Enabled = false;
					m_distanceValueUD.Enabled = false;
				}
			}

			m_currentRepresentationClass = repClass;
		}
		private void ClickHandler(object sender, System.EventArgs e)
		{
			if (sender == m_dictionaryBtn) this.AddFile(m_dictionaryTB,"Choose dictionary file");
			else if (sender == m_graphRB) this.SetRepresentationClass(RepresentationClass.Graph);
			else if (sender == m_vectorRB) this.SetRepresentationClass(RepresentationClass.Vector);
			else if (sender == m_clustersAddBtn) this.AddClusters(m_clustersLV);
			else if (sender == m_clustersClearBtn) this.ClearClusterList();
			else if (sender == m_proceedBtn) this.ProceedThread();
			else if (sender == m_graphRepCB) this.SetRepresentationClass(RepresentationClass.Graph);
			else if (sender == m_seriesPathBtn) this.SetSeriesPath();
			else if (sender == m_cosineDistanceRB) m_currentDistanceType = DistanceType.Cos;
			else if (sender == m_jacaardDistanceRB) m_currentDistanceType = DistanceType.Jacaard;
			else if (sender == m_mcsDistanceRB) m_currentDistanceType = DistanceType.Mcs;
			else if (sender == m_wguDistanceRB) m_currentDistanceType = DistanceType.Wgu;
		}
		private void AddFile(Control control,string message)
		{
			openFileDialog.Title = message;
			openFileDialog.Multiselect = false;
			if (DialogResult.OK == openFileDialog.ShowDialog())
			{
				control.Text = openFileDialog.FileName;
			}
		}
		private void AddClusters(ListView list)
		{
			openFileDialog.Title = "Choose cluster files";
			openFileDialog.Multiselect = true;
			string [] files;
			if (DialogResult.OK == openFileDialog.ShowDialog())
			{
				files = openFileDialog.FileNames;
				list.BeginUpdate();
				foreach(string file in files)
				{
					list.Items.Add(file);
				}
				list.EndUpdate();
			}
		}
		private void ClearClusterList() { m_clustersLV.Items.Clear();}

		private void SetSeriesPath()
		{
			if (DialogResult.OK == folderBrowserDialog.ShowDialog())
			{
				m_seriesPathTB.Text = folderBrowserDialog.SelectedPath;
				if (m_seriesPathTB.Text[m_seriesPathTB.Text.Length - 1] != '\\')
								m_seriesPathTB.Text = folderBrowserDialog.SelectedPath + "\\";
			}
		}

		private void ProceedThread()
		{
			Thread thread = new Thread(new ThreadStart(this.Proceed));
			thread.IsBackground = true;
			thread.Start();
		}
		private void Proceed()
		{
			try
			{
				string dictionaryFile = m_dictionaryTB.Text;
				string seriesPath = m_seriesPathTB.Text;
				ListView.ListViewItemCollection clusterFiles = m_clustersLV.Items;
				int distanceValue = (int)m_distanceValueUD.Value;

				m_currentGraphRepresentationType = (GraphRepresentationType) m_graphRepCB.SelectedItem;
				m_currentVectorRepresentationType = (VectorRepresentationType) m_vectorRepCB.SelectedItem;

        m_resultMediator.Proceed(dictionaryFile,seriesPath,clusterFiles,
					                       m_currentGraphRepresentationType,
					                       m_currentVectorRepresentationType,
					                       m_currentRepresentationClass,
					                       m_currentDistanceType,
																 distanceValue
					                      );
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message, "Proceed Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

	}
}
